package com.disys.facade;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.mapping.Array;

import com.disys.dao.Rec140ERWOTCLOCDAO;
import com.disys.model.Process;
import com.disys.model.Rec140ERWOTCLOC;

/**
 * @author Ubaid Raja
 *
 */
public class Rec140ERWOTCLOCFacade {
	private Rec140ERWOTCLOCDAO obj = new Rec140ERWOTCLOCDAO();
	
	public List<Rec140ERWOTCLOC> findAllRecords(){
		
		List<Rec140ERWOTCLOC> list = null;
		try{
			obj.beginTransaction();	
			list = obj.findAll();
			obj.closeTransaction();
		}catch(IllegalStateException ex){
			list = obj.findAllSorted("Process");
			obj.closeTransaction();
		}
		if(list.size() ==0 || list == null){
			return new ArrayList<Rec140ERWOTCLOC>();
		}
		return list;
	}
	
	public List<Rec140ERWOTCLOC> findFinalizeRecords(String object,Integer isFinalized, BigInteger pId){
		//obj.beginTransaction();
		List<Rec140ERWOTCLOC> list = obj.findFinalizeRecords(object,isFinalized,pId);
		//obj.closeTransaction();
		if(list.size() ==0 || list == null){
			return new ArrayList<Rec140ERWOTCLOC>();
		}
		return list;
	}

	public void insertRecord(Rec140ERWOTCLOC entity){
		obj.saveRecord(entity);
		//obj.commit();
	}
	
	public List<Integer> getAllProcessIds(String object) {
		obj.beginTransaction();
		List<Integer> list = obj.getAllProcessIds(object);
		obj.closeTransaction();
		return list;
	}
	
	
	public List<Rec140ERWOTCLOC> findSelectedProcessRecords(String object,BigInteger processId){
		List<Rec140ERWOTCLOC> list = null;
			obj.beginTransaction();	
			list = obj.findSelectedProcessRecords(object,processId);
			obj.closeTransaction();
		if(list.size() ==0 || list == null){
			return new ArrayList<Rec140ERWOTCLOC>();
		}
		return list;
	}
}
